<div id="openmain">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="ntModalLabel">{$title}</h4>
        <input type="hidden" name="" id="id" value="{$id|default=''}">
        <input type="hidden" name="" id="requestType" value="{$requestType|default=''}">
    </div>
    <div class="modal-body">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="alert alert-dismissable alert-info">
                    <button type="button" class="close">×</button>
                    <p></p>
                </div>
            </div>
        </div>
        <table class="table table-striped table-hover ntTable" style="padding-top:0">
            <tbody>
                <tr>
                    <td>代号<span class="required"></span></td>
                    <td><input type="text" class="form-control" placeholder="代号" v-model="code"></td>
                </tr>
                <tr>
                    <td>名称<span class="required"></span></td>
                    <td><input type="text" class="form-control" placeholder="名称" v-model="name"></td>
                </tr>
                <tr>
                    <td>排序<span class="required"></span></td>
                    <td><input type="number" class="form-control text-right" placeholder="排序"  v-model="sort"></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>取消</button>
        <button type="button" class="btn btn-primary" style="padding-left:24px;padding-right:24px" @click="saveFun"><span class="glyphicon glyphicon-floppy-disk"></span>保存</button>
    </div>
</div>
<script>
    new Vue({
        el:'#openmain',
        data:()=>({
            code:'',
            name:'',
            sort:100,
            olddrank:1
        }),
        created(){
            if($('#requestType').val()=='edit'){
                $.ajax({
                    url:'/admin/saledeliverytype/deliverytypeedit?request=edit&id='+$('#id').val(),
                    type:'post',
                    success:data=>{
                        data=JSON.parse(data).data
                        this.code=data.code
                        this.name=data.content
                        this.sort=data.drank
                        this.olddrank=data.olddrank
                    }
                })
            }
        },
        methods:{
            saveFun(){
                if($('#requestType').val()=='edit'){
                    var url = '/admin/saledeliverytype/deliverytypeedit?request=update&id='+$('#id').val();
                }else{
                    var url = '/admin/saledeliverytype/deliverytypeAdd?request=insert';
                }
                $.ajax({
                    url:url,
                    type:'post',
                    data:{
                        code:this.code,
                        content:this.name,
                        drank:this.sort,
                        olddrank:this.olddrank
                    },
                    success:data=>{
                        data=JSON.parse(data)
                        change_mes_type('.alert',data.status)
                        if(data.status==1){
                            $('.alert').show()
                            $('.alert p').html('*'+data.msg+'<br>')
                            $('#delivery_type_Modal').modal('toggle')
                            //this.getData()
                        }else{
                            $('.modal-body .alert').show()
                            $('.modal-body .alert p').html('*' + data.msg + '<br>')
                        }
                    }
                })
            }
        }
    })
</script>